using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FutureOpen.Core.func.sql;
using FutureOpen.Core.func;
using FutureOpen.Web.Pages;


public partial class controls_BlogList : System.Web.UI.UserControl
{
    private PageBase pbase;
    private int uid;
    private static int PAGE_SIZE = 20;

    protected void Page_Load(object sender, EventArgs e)
    {
        pbase = (PageBase)this.Page;
        pbase.PageInit();

        if (pbase.usrid > 0)
        {
            uid = pbase.usrid;
        }
        else
        {
            uid = pbase.MyUsr;
        }

        if (!Page.IsPostBack)
        {            
            {
                AspNetPager1.PageSize = PAGE_SIZE;
                AspNetPager1.RecordCount = TopicProvider.GetTopicByUsrTypeCount(uid, TopicProvider.TOPIC_TYPE_BLOG);
                BindBlogs(0);
            }
        }
    }
        
    protected void lbDeleteBlog_Click(object sender, EventArgs e)
    {
        LinkButton lbt = (LinkButton)sender;
        string id = lbt.CommandArgument;
        int blogid = int.Parse(id);
        TopicProvider.DelTopic(blogid);
        Response.Redirect("MyBlog.aspx");
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindBlogs(PAGE_SIZE * (e.NewPageIndex - 1));
    }

    private void BindBlogs(int start)
    {
        DataSet ds = TopicProvider.GetTopicByUsrType(uid, TopicProvider.TOPIC_TYPE_BLOG, start, PAGE_SIZE);
        this.DataList1.DataSource = ds.Tables[0];
        this.DataList1.DataBind();
    }
    public string Shorten200(object obj)
    {
        string str = obj.ToString();
        if (str.Length > 50)
        {
            return str.Substring(0, 47) + "..."; 
        }
        return str;
    }
}
